package com.xxx.coll;

import java.util.Objects;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/20 16:19
 * @Copyright 博为峰
 */
public class Worker implements Comparable {
    private String name;
    private int age;

    public Worker() {
    }

    public Worker(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        System.out.println(this);
        System.out.println("equals");
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Worker worker = (Worker) o;
        return age == worker.age && name.equals(worker.name);
    }

    @Override
    public int hashCode() {
        System.out.println("hashCode");
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Object o) {
//        System.out.println("compareTo");
//        System.out.println(this.name);
        Worker worker = (Worker) o;
//        System.out.println(worker.name);
        return worker.name.compareTo(this.name);
    }
}
